package com.eff.android.api.model;

import java.util.ArrayList;
import java.util.List;

import android.graphics.AvoidXfermode.Mode;
import android.util.Log;
    
public class Subject {		
	
	private List<ModelSubject> subjectType;
	private int value;
	    
	public Subject() {
		subjectType = new ArrayList<ModelSubject>();
		value = -1;
	}
	
	public Subject(List<ModelSubject> subjectType, int value){
		this.subjectType = subjectType;
		this.value = value;
	}
	    
	private static Subject instance = null;
	
	public static Subject getInstance() {
		if (instance == null)
			instance = new Subject();
		return instance;
	}
	
	public void setSubject(Subject subject) {
		instance = subject;
	}
	
	public List<ModelSubject> getListType() {
		return subjectType;
	}
	
	public void setListType(List<ModelSubject> type) {
		subjectType = type;
	} 
	
	public int getValue() {
		return this.value;
	}
	
	public void setValue(int value) {
		this.value = value;
	}
	
	public ModelSubject getType() {
		if (this.value == -1)
			return new ModelSubject();
		return subjectType.get(this.value);
	}
	
	public ModelSubject getTypePosAt(int value) {
		return subjectType.get(value);
	}
	
	public void setType(String type) {
		
		Log.d("Subject Choose Input: ", type);
		Log.d("Value Before: ", String.valueOf(this.value));
		
		if (type.compareTo("mixed") == 0)
			this.value = -1;
		else {
			
			for (int i = 0; i < subjectType.size(); i++) {
				//Log.d("Compare " + String.valueOf(i), subjectType.get(i).toString().toLowerCase() + " vs" + type.toString());
				if (subjectType.get(i)._subject_name.toString().toLowerCase().compareTo(type) == 0) {
					this.value = i;
				}			
			}
		}
		
		
		Log.d("Value After: ", String.valueOf(this.value));
	}
	
	public void addType(ModelSubject type) {
		this.subjectType.add(type);
	}
	
	public String getSubjectName() {
		if (this.value == -1)
			return "Mixed";
		return subjectType.get(this.value)._subject_name.toString();
	}
}
